﻿function Widget_Html(obj)
{
   this.initializeBase(obj);
}
Widget_Html.prototype = new WidgetInstance;

Widget_Html.prototype.EditorLoaded = function()
{
   this.Widget.InstanceEdit('ws_' + this.id + '_txt');

   if (!this.FreeTextBox)
   {
	   this.FreeTextBox = new Refresh.Web.FreeTextBox('ws_' + this.id + '_txt', {
		      styleSheetUrls:['/refresh_web/ftb.css'],
		      theme:'simple',
		      toolbarGroups: [
			      {
				      title: 'Font',
				      items: [
					      {name:'Bold'},
					      {name:'Italic'},
					      {name:'Underline'},
					      {name:'BulletedList'},
					      {name:'NumberedList'},
					      {name:'CreateLink'},
					      {name:'Unlink'}					
				      ]
			      }	
		      ]
	      });	
	   }
}

Widget_Html.prototype.Edit = function()
{
   if (myTabs.hasRequiredTabPermission(this.Tab, TabAccessLevel.Widget_Edit))
   {
      setTimeout(Function.createDelegate(this, this.EditorLoaded), 1);   
   }
}

Widget_Html.prototype.Save = function()
{
   if (myTabs.hasRequiredTabPermission(this.Tab, TabAccessLevel.Widget_Edit))
   {
      //Save
      var val = $("ws_" + this.id + "_txt").value;
      this.WidgetDiv_BodyContent.innerHTML = val; 
      
      //if there is javascript inside the nodes, need to execute them
      execJS(this.WidgetDiv_BodyContent);

      JSON.Widget_UpdateProperty(this.Widget.Tab.id, this.id, "state", val);
      
      this.inEditMode = true;
      this.Edit();
   }
}
   
Widget_Html.prototype.Refresh = function()
{
   this.FreeTextBox = null;
   this.InstanceRefresh();
}

Widget_Html.prototype.Load = function()
{
   this.Widget.InstanceLoad();
   
   this.WidgetDiv_BodyContent = document.getElementById("wdivbc" + this.Widget.id);
   this.WidgetDiv_BodySettings = document.getElementById("wdivbs" + this.Widget.id);
   this.WidgetDiv_Command_Edit = document.getElementById("wdivc_edit" + this.Widget.id);
   
   if (this.Widget.obj.State && this.Widget.obj.State.length > 0)
   {
      this.WidgetDiv_BodyContent.innerHTML = this.Widget.obj.State; 
      $("ws_" + this.id + "_txt").value = this.Widget.obj.State; 
      execJS(this.WidgetDiv_BodyContent);
   }

   this.Widget.InstanceLoadComplete();
   
   //just queue the html editor files first
   //no need to queue prototype because scriptalicious alreayd loads it
   //installScriptSrc('/refresh_web/prototype.js');
   //installScriptSrc('/refresh_web/ftb.js');   
}